package com.netease.login.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Repository;

import com.netease.meta.User;

@Repository
public class UserDao {
	@Autowired
	private JdbcTemplate jdbcTemplate;
	public int getMatchCount(String userName,String userPassword){
		String sqlStr = "SELECT count(*) FROM User WHERE userName = ? and userPassword = ?";
		return jdbcTemplate.queryForObject(sqlStr,new Object[]{userName,userPassword},Integer.class);		
	}
    public User findUserByName(final String userName){
    	String sqlStr = "SELECT userId,userName FROM User WHERE userName = ?";
    	final User user = new User();
    	jdbcTemplate.query(sqlStr, new Object[]{userName},new RowCallbackHandler(){

			@Override
			public void processRow(ResultSet rs) throws SQLException {
				user.setUserId(rs.getInt("userId"));
				user.setUserName(userName);
				
			}
    		
    	});
		return user;
    	
    }
}
